﻿namespace UrlShortenerDemo
{
    using System;
    using System.Reactive.Linq;
    using System.Windows;
    using Microsoft.Phone.Controls;
    using WP7Contrib.Services.UrlShorteners;

    public partial class MainPage : PhoneApplicationPage
    {
        private readonly IShortenUrls tinyUrlShortener;

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.url.Text = "http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27570";
            
            this.tinyUrlShortener = new TinyUrlShortener();
        }

        private void HandleShortenButtonClick(object sender, RoutedEventArgs e)
        {
            this.tinyUrlShortener.Shorten(this.url.Text)
                .ObserveOnDispatcher()
                .Subscribe(u => this.shortenedUrl.Text = u);
        }
    }
}